﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MQ.Core.Cache;
using MQ.Core.Db;
using MQ.Core.Db.MySql;
using MQ.Core.Db.SqlServer;
using MQ.Core.IRepository;
using MQ.Core.IRepository.System;
using MQ.Core.IService;
using MQ.Core.IService.System;
using MQ.Core.Repository;
using MQ.Core.Repository.System;
using MQ.Core.Service;
using MQ.Core.Service.System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;

namespace MQ.Core.Admin.Areas.System
{
    /// <summary>
    /// 
    /// </summary>
    public static class SystemExtension
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="services"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IServiceCollection AddSystem(this IServiceCollection services,IConfiguration config)
        {
            var dbOption = new DbOption(config);
            var redisOption = new RedisOption(config);
            services.Add(ServiceDescriptor.Singleton(redisOption));
            services.Add(ServiceDescriptor.Singleton(dbOption));
            services.AddDbContext<MqDbContext>(options => options.UseSqlServer(dbOption.DefaultConnection));
            services.AddDbContext<MyDbContext>(options => options.UseMySQL(dbOption.MySqlConnection));
            services.AddTransient<ISqlDb, SqlDb>();
            #region repositorys
            services.AddTransient<IDictionaryRepository, DictionaryRepository>();
            services.AddTransient<ILogRepository, LogRepository>();
            services.AddTransient<ICompanyRepository, CompanyRepository>();
            services.AddTransient<IAreaRepository, AreaRepository>();
            services.AddTransient<IUserRepository, UserRepository>();
            services.AddTransient<IDictionaryTypeRepository, DictionaryTypeRepository>();
            services.AddTransient<IDepartmentRepository, DepartmentRepository>();
            #endregion
            #region services
            services.AddTransient<IDictionaryService, DictionaryService>();
            services.AddTransient<ILogService, LogService>();
            services.AddTransient<ICompanyService, CompanyService>();
            services.AddTransient<IAreaService, AreaService>();
            services.AddTransient<IDictionaryTypeService, DictionaryTypeService>();
            services.AddTransient<IUserService, UserService>();
            services.AddTransient<IDepartmentService, DepartmentService>();
            #endregion

            return services;
        }
    }
}
